<?php
/*
 * Created on 28/06/2009
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
include_once 'DataBase.php';

class Conexion{
 
 	private $dataBase;
 	
 	function Conexion()
 	{
 		$this->dataBase=new DataBase();
 	}
 	
 	public function getConnect()
 	{
 		return mysql_connect($this->dataBase->getHost(),$this->dataBase->getUser(),$this->dataBase->getPass()); 
 	}
 	
 	public function getConexion()
 	{ 	
 		$link= $this->getConnect();
 		
 		mysql_select_db($this->dataBase->getDataBase(), $link);
 		
 		return $link; 
 		
 	}
 	
 	public function ejecutarQuery($query)
 	{
 		$link= $this->getConexion();
 	
 		return mysql_query($query, $link); 
 	}
 	
	function secuencia($tabla) {
		
		$sql="select * from sequence_numbers where table_name='".$tabla."'";
		
		//echo $sql;
				
		$result = $this->ejecutarQuery($sql);
		
		$row=mysql_fetch_array($result);
		
		$valor= $row["next_id"];
		
		$nuevovalor=$valor+1;
		
		$sqlUpdate="update sequence_numbers set next_id='".$nuevovalor."' where table_name='".$tabla."' ";
			
		$this->ejecutarQuery($sqlUpdate);
		
		return $nuevovalor;
		
	}
 	
 }
?>
